<template>
  <div class="tpl44-swiper">
    <!-- 折叠轮播 -->
    <div ref="getHeight"  class="imgAdv-box">
      <!-- TODO 小程序端用swiper -->
      <wx-swiper class="my-swipe" :style="`height: ${imgadvWxH}`" :circular="true" indicator-active-color="#ffffff" :autoplay="autoplay" :indicator-dots="showIndicators">
        <wx-swiper-item v-for="(item,index) in tplItemData.dataset" :key="index">
          <a @click="openPage(item.link)">
            <img class="img" :src="item.pic" alt="" @load="onImageLoad($event)"/>
          </a>
        </wx-swiper-item>
      </wx-swiper>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Swipe, SwipeItem } from 'vant'
import { openPage } from '@/utils/utils'
Vue.use(Swipe)
Vue.use(SwipeItem)
export default Vue.extend({
  props: {
    tplItemData: {
      type: Object // 传入参数的类型
    }
  },
  data() {
    return {
      imgadvWxH:'0',
      showIndicators: true,
      autoplay: true
    }
  },
  methods: {
    // TODO 小程序跳转
    openPage(link) {
      openPage(link)
    },
    // TODO 小程序swiper获取图片高度
    onImageLoad(event){
      const imgHeight=event.detail.height
      if(imgHeight>parseFloat(this.imgadvWxH)){
        this.imgadvWxH=imgHeight+'px'
      }
    }
  },
})
</script>

<style lang="scss">
@import "src/styles/mixin";
</style>
